package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

//归还图书操作
public class ReturnOperation implements IOperation {
    @Override
    public void work(BookList bookList) {
        System.out.println("归还图书！");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入归回图书的名字：");
        String name = scanner.nextLine();

        int currentSize = bookList.getUsedSize();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBooks(i);
            if (book.getName().equals(name) ) {
                if (book.isBorrowed() == true) {
                    System.out.println("归还成功！");
                    book.setBorrowed(false);
                    return;
                } else {
                    System.out.println("该书没有被借出！");
                }
                return;
            }
        }
        System.out.println("你归还的图书不存在！");
    }
}
